package com.tonyodev.fetch2;

import org.jetbrains.annotations.NotNull;

import java.io.Serializable;

/**
 * An object that represents a Fetch download notification.
 *
 * @since 2021-05-20
 */
public class DownloadNotification implements Serializable {

    @NotNull
    private Status status;
    private int progress;
    private int notificationId;
    private int groupId;
    private long etaInMilliSeconds;
    private long downloadedBytesPerSecond;
    private long total;
    private long downloaded;
    @NotNull
    private String namespace;
    @NotNull
    private String title;

    @NotNull
    public Status getStatus() {
        return this.status;
    }

    public void setStatus(@NotNull Status var1) {
        this.status = var1;
    }

    public int getProgress() {
        return this.progress;
    }

    public void setProgress(int var1) {
        this.progress = var1;
    }

    public int getNotificationId() {
        return this.notificationId;
    }

    public void setNotificationId(int var1) {
        this.notificationId = var1;
    }

    public int getGroupId() {
        return this.groupId;
    }

    public void setGroupId(int var1) {
        this.groupId = var1;
    }

    public long getEtaInMilliSeconds() {
        return this.etaInMilliSeconds;
    }

    public void setEtaInMilliSeconds(long var1) {
        this.etaInMilliSeconds = var1;
    }

    public long getDownloadedBytesPerSecond() {
        return this.downloadedBytesPerSecond;
    }

    public void setDownloadedBytesPerSecond(long var1) {
        this.downloadedBytesPerSecond = var1;
    }

    public long getTotal() {
        return this.total;
    }

    public void setTotal(long var1) {
        this.total = var1;
    }

    public long getDownloaded() {
        return this.downloaded;
    }

    public void setDownloaded(long var1) {
        this.downloaded = var1;
    }

    @NotNull
    public String getNamespace() {
        return this.namespace;
    }

    public void setNamespace(@NotNull String var1) {
        this.namespace = var1;
    }

    @NotNull
    public String getTitle() {
        return this.title;
    }

    public void setTitle(@NotNull String var1) {
        this.title = var1;
    }

    public boolean isActive() {
        return this.status == Status.QUEUED || this.status == Status.DOWNLOADING;
    }

    public boolean isPaused() {
        return this.status == Status.PAUSED;
    }

    public boolean isFailed() {
        return this.status == Status.FAILED;
    }

    public boolean isCompleted() {
        return this.status == Status.COMPLETED;
    }

    public boolean isDownloading() {
        return this.status == Status.DOWNLOADING;
    }

    public boolean isCancelled() {
        return this.status == Status.CANCELLED;
    }

    public boolean isDeleted() {
        return this.status == Status.DELETED;
    }

    public boolean isRemoved() {
        return this.status == Status.REMOVED;
    }

    /**
     * Returns true if the download queued.
     *
     * @return true
     */
    public boolean isQueued() {
        return this.status == Status.QUEUED;
    }

    /**
     * Returns true if the download notification is ongoing.
     *
     * @return true
     */
    public boolean isOnGoingNotification() {
        if (status == Status.QUEUED || status == Status.DOWNLOADING) {
            return true;
        }
        return false;
    }

    /**
     * Returns true if the download notification was cancelled.
     *
     * @return download
     */
    public boolean isCancelledNotification() {
        if (status == Status.DELETED || status == Status.REMOVED || status == Status.CANCELLED) {
            return true;
        }
        return false;
    }

    /**
     * Returns true if the download notification is removable.
     *
     * @return true
     */
    public boolean isRemovableNotification() {
        if (status == Status.COMPLETED
            || status == Status.FAILED
            || status == Status.CANCELLED
            || status == Status.REMOVED
            || status == Status.DELETED) {
            return true;
        }
        return false;
    }

    public boolean getProgressIndeterminate() {
        return this.total == -1L;
    }

    /**
     * Download Action Types used by the FetchNotificationBroadcastReceiver.
     *
     * @since 2021-06-17
     */
    enum ActionType {
        /**
         * Paused an ongoing download.
         */
        PAUSE,
        /**
         * Resumes a paused download.
         */
        RESUME,
        /**
         * Cancels a download.
         */
        CANCEL,
        /**
         * Delete a download.
         **/
        DELETE,
        /**
         * Retry failed downloads.
         */
        RETRY,
        /**
         * Pause ongoing downloads.
         */
        PAUSE_ALL,
        /**
         * Resume paused downloads.
         */
        RESUME_ALL,
        /**
         * Cancel downloads.
         */
        CANCEL_ALL,
        /**
         * Delete downloads.
         */
        DELETE_ALL,
        /**
         * Retry downloads.
         */
        RETRY_ALL;
    }

    @Override
    public String toString() {
        return "DownloadNotification (" +
            "status=" + status +
            ", progress=" + progress +
            ", notificationId=" + notificationId +
            ", groupId=" + groupId +
            ", etaInMilliSeconds=" + etaInMilliSeconds +
            ", downloadedBytesPerSecond=" + downloadedBytesPerSecond +
            ", total=" + total +
            ", downloaded=" + downloaded +
            ", namespace='" + namespace + '\'' +
            ", title='" + title + '\'' +
            ')';
    }
}
